<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="cn.estore.dao.ProductDao" %>
<%@ page import="cn.estore.entity.ProductEntity" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<table border="0" width="1024" align="center">
    <tr>
        <%--        顶部--%>
        <td colspan="6">
            <jsp:include page="../Common/head.jsp" flush="true"/>
        </td>
    </tr>
    <tr>
        <td width="300" bgcolor="#F5F5F5" valign="top">
            <%--            左侧--%>
            <jsp:include page="../Common/left.jsp" flush="true"/>
        </td>
        <td width="724" align="center" valign="top" bgcolor="#FFFFFF">
            <%--            右侧--%>
            <div align="left">
                <img src="/javaweb_war/systemImages/fg_right03.jpg">
            </div>
                <%
    //新品查询
    ProductDao dao = new ProductDao();
    List originalList = null;
    originalList = dao.selectProductsDiscount(new Integer(0));
%>

                <%
    int pageNumber = originalList.size();//计算出记录总数
    int maxPage = pageNumber;//计算出有多少页数
    String strNumber = request.getParameter("pageNum");
    int number = 0;//待显示页码，默认为第一页
    if (maxPage % 4 == 0) {
        maxPage = maxPage / 4;//最多页数，能整除的，结果为页数
    } else {
        maxPage = maxPage / 4 + 1;//不能整除的，结果加一
    }
    if (strNumber == null) {//表明在QueryString中没有pageNum这一个参数，此时显示第一页数据
        number = 0;
    } else {
        number = Integer.parseInt(strNumber);//取得待显示页码，将字符串转换为整型
    }
    int start = number * 4;//开始读取数据位置
    int over = (number + 1) * 4;//结尾数据位置
    int count = pageNumber - over;//还剩多少条记录
    if (count <= 0) {
        over = pageNumber;//避免越界
    }
%>
                <%
    for (int i = start; i < over; i++) {
        ProductEntity originalGoods = (ProductEntity) originalList.get(i);

%>
            <table width="95%" height="136" border="1" align="center" cellpadding="1" cellspacing="1"
                   bordercolor="#FFFFFF" bgcolor="#999999">
                <tr>
                    <td width="40%" height="80" rowspan="5" bgcolor="#FFFFFF">
                        <div align="center">
                            <img src="<%="/javaweb_war/productImages/"+originalGoods.getPictrue()%>" width="110"
                                 height="100"
                                 alt="">
                        </div>
                    </td>
                    <td width="59%" bgcolor="#FFFFFF">
                        <div align="left">商品:<%=originalGoods.getName()%>
                        </div>
                        <div align="left">单价:<%=originalGoods.getMarkPrice()%>元
                        </div>
                        <div align="left">简介:<%=originalGoods.getDescription()%>
                        </div>

                    </td>
                </tr>
            </table>
                <%
    }

%>

            <table>
                <tr align="center" style="width: 1024px;">
                    <td style="width: 13%">共为<%=maxPage%>页</td>
                    <td style="width: 18%">共有<%=pageNumber%>条记录</td>
                    <td style="width: 26%">当前为第<%=number + 1%>页</td>

                    <td style="width: 15%">
                        <%
                            if ((number + 1) == 1) {//目前显示的是第一页
                        %>
                        上一页
                        <% } else {%>
                        <a href="showProductOriginal.jsp?pageNum=<%=number-1%>">上一页</a>
                    </td>
                    <%}%>
                    <td style="width: 14%">
                        <%
                            if (maxPage <= (number + 1)) {//目前显示的是最后一页
                        %>
                        下一页
                        <%} else {%>
                        <a href="showProductOriginal.jsp?pageNum=<%=number+1%>">下一页</a>
                    </td>
                    <%}%>

                </tr>
            </table>


    <tr>

        <%--        底部--%>
        <td colspan="2">

            <jsp:include page="../Common/statusBarNavigation.jsp" flush="true"/>
        </td>
    </tr>
</table>
</table>
</body>
</html>